The present invention relates to a two-dimensional code reading apparatus, two-dimensional code reading process, two-dimensional code reading program, recording medium for said program, portable terminal and digital camera, and in particular to a two-dimensional code reading apparatus, two-dimensional code reading process, two-dimensional code reading program and recording medium for said program, which enables, for example, a portable terminal having a built-in camera to easily read two-dimensional codes.
Portable cellular phones having built-in cameras have recently been becoming popular. If information which is recorded in two-dimensional code is read by picking up the images of the two-dimensional code by means of a camera which is incorporated in such a portable cellular phone, it is necessary to make it possible to read the two-dimensional code by a technique having a comparatively less processing capacity in view of the processing capacity since usual portable cellular phones have a low processing capacity.
Examples of two-dimensional code include two-dimensional code, that is QR code (Quick Response Code) which is prescribed by JISX510 (and ISO/IEC 18004). FIG. 1 is a schematic view showing an exemplary configuration of QR code. As shown in FIG. 1, the two-dimensional QR code which is in the shape of square is configured so that the position of QR code can be detected. A specific first pattern (finder pattern F) comprising squares having different size proportions is disposed at each of three corners of the two-dimensional code. A reference pattern (timing pattern T) comprising black and white cells which are alternately arrayed in a lateral and vertical directions is disposed among the three finder pattern F. The timing pattern T is an index of the position of each data cell of the two-dimensional code. A specific second pattern (alignment pattern P) is disposed on the two-dimensional code, which makes it possible to conduct alignment of the positions of the data cells of the two-dimensional code even if the two-dimensional code is imaged in a obliquely distorted manner.
The inner area of the QR code is divided into m by m square areas (hereinafter referred to as “cells”). Binary data which is light (white) and dark (black) cell can be recorded in each cell. The finder pattern is a figure comprising a black square having sides, the length of each of which corresponds to seven cells, a white square having sides, the length of each of which corresponds to five cells and a black square having sides, the length of each of which corresponds to three cells which are concentrically superposed in a radial outward direction.
The image of the thus formed QR code is read by means of image sensor and is input into two-dimensional code reading apparatus. The image which is input to the two-dimensional code reading apparatus is converted into two-value, or binary image having any of two values such as light (white) and dark (black). In such a manner reading of the two-dimensional code is accomplished for the binary image.
The two-dimensional code is configured so that ratio of appearances of black:white:black:white:black cells in the finder pattern F when the binary image is linearly scanned in a lateral or vertical direction in the vicinity of the center of the finder pattern F having the above-mentioned size is 1:1:3:1:1. By using the ratio of appearance of the pattern having such ratio, the position of the finder pattern F can be detected from the binary image which has been input from the image sensor and converted into binary data.
If the finder pattern F which is positioned at the opposite ends of the timing pattern T is detected, the timing pattern T can be detected by detecting the position at which black and white cells alternately appear at a ratio of 1:1 from the end of the finder pattern F.
If the image of the QR code is picked up obliquely, a distortion of the picked up image depending upon the imaging direction occurs in comparison to the image which is picked up in a normal direction with respect to the QR code. In order to make it possible to correctly determine the cell position of the QR code for the distorted image, the alignment pattern P comprising specific second pattern is disposed in a given position in the two-dimensional code, different from that of the finder pattern F with reference to the finder pattern F.
The two-dimensional code is configured so that the coordinates of the alignment pattern P which is expected to be disposed can be calculated from the coordinates of the centers of the three finder patterns F. By examining the binary image consecutively in detail based upon the result of the calculation to extract a partial pattern comprising a shape matching with the feature of the second pattern which is specific to the alignment pattern P, the position of the alignment pattern P can be detected.
The coordinates of the position of the center of each data cell in which data is recorded can be calculated from each coordinate at which respective positions of the finder patterns F, timing pattern T and alignment pattern P is detected. An example will be described with reference to FIG. 2 showing the manner of conventional data cutting out.
FIG. 2 is a schematic view showing the prior art which calculates the coordinates of the center of data cell in the QR code. In FIG. 2, the centers of the finder patterns F are represented as Fa, Fb and Fc and the center of the alignment pattern P is represented as Pd. Firstly, a straight line S1 which connects point Fb with point Fb and a straight line S4 which connects point Fa with point Fc are determined.
A point Fb′ to which the point Fb has been moved by three cells in a horizontal direction (lateral direction) and in a leftward direction (that is, in a direction toward the point Fa) on the straight line S1 is determined. Then, a point Fc′ to which the point Fc which has been moved by three cells in a vertical direction and in an upward direction (that is, in a direction toward the point Fa) on the straight line S1 is determined.
A straight line S3 which connects the moved point Fb′ with the center point Pd of the alignment pattern P is determined and a straight line S2 which connects the moved point Fc′ with the center point Pd of the alignment pattern P is determined.
The coordinates of the center of each cell in the position which is designated by a mark E in FIG. 2 is found from the center points Fa and Fb of the finder patterns F which are disposed in a horizontal (lateral) direction and the timing pattern T which is disposed therebetween.
Further, the inclination of a straight line (for example, a dotted line Hs is shown in FIG. 2) which is a horizontal reference, passing through the center of each cell represented by mark E can be calculated from the inclinations of the lines S4 and S3, so that a horizontal reference line Hs passing through the center of each of cells represented by mark E can be determined.
Similarly, vertical reference lines Vs can be also determined. The position in which thus determined horizontal reference line Hs intersects with vertical reference line Vs can be calculated as the coordinates of the center of each data cell.
The appearance frequency of black and white cells is sequentially checked towards the peripheral of the data cells from the thus calculated coordinates of the centers of the cells and the number of the white pixels in the cell is compared with that of the black pixels, so that more pixels are determined as data value of the data cells in interest.
When the position of the QR code which is a two-dimensional code is to be identified, it is necessary to determine whether or not the ratio of the black:white:black:white:black pattern of cells is 1:1:3:1:1 in order to detect the finder pattern F. However, if the image in which the two-dimensional code (QR code) is rotated or tilted is picked up, said ratio for detecting the finder pattern F may not exactly match said ratio of 1:1:3:1:1 even if the appearance frequency is tried to determine only in a horizontal or vertical direction. A case may occur in which the detected ratio matches said ratio 1:1:3:1:1 in a position other than the position in which actual finder pattern F exists. The position of the finder pattern F may be incorrectly detected.
If the timing pattern T is detected and is used in order to determine the positions of data cells, there is a problem that an extended period of time is required to detect the timing pattern T in which white and black cells alternately appear between the finder patterns F which are positioned at three corner of the two-dimensional code (QR code). This problem becomes more serious as the version of the two-dimensional code (QR code) become newer (more number of pixels forming the two-dimensional code).
The alignment pattern P is detected by calculating expected coordinates at which it is expected that the alignment pattern P exists from the coordinates of the finder pattern F and by examining the peripherals in detail. Since the expected coordinates may largely deviate from the coordinates in which actual alignment pattern P exists due to the distortion of the picked up image, a great deal of time would be required to conduct examination to detect exact position in which the actual alignment pattern P exists.
Precise examination of the alignment pattern P of the two-dimensional code (QR code) is conducted for the binary image which has been subjected to binary processing. Crushing of white pixels and chipping of black pixels may occur due to an error which is caused by conversion into binary data. A problem may occur in which the alignment pattern P is incorrectly detected by the influence of such crushing or chipping.
The two-dimensional code (QR code) having the cells which is large in number to some extent can be formed in such a manner that a plurality of alignment patterns P are disposed and the data cells can be stably cut out from the two-dimensional data (i.e. the data value of each data cell can be determined) by detecting any of a plurality of alignment patterns P even through the pick up image is slightly distorted. In this case, it is necessary to detect the position of a plurality of alignment patterns P, so that an extended period of time is taken to complete processing.
Since the data values of data cells are determined (i.e. the data cells are cut out) by checking the numbers of the black and white pixels within a specified range based upon the dimensions of the cell, i.e. the cell size, an extended period of time is not only required to determine the data values of the data cells, but also crushing of white pixels and chipping of black pixels is liable to occur due to an error in binary processing (binarization), so that the data values of the data cells is liable to be erroneous.
An error may occur due to distortion of the input image when the version of said two-dimensional code (QR code) is determined by calculating the number of cells from the distance between the finder patterns F. Accordingly, correct version of the code can not be determined, so that reading of the two-dimensional code fails.